#ifndef __VEML7700_H__
#define __VEML7700_H__
#include <wiringPi.h>
#include <wiringPiI2C.h>
#include <stdint.h>

  enum als_gain_t
  { ALS_GAIN_x1 = 0x0,    // x 1
    ALS_GAIN_x2 = 0x1,    // x 2
    ALS_GAIN_d8 = 0x2,    // x 1/8
    ALS_GAIN_d4 = 0x3 };  // x 1/4
  enum als_itime_t
  { ALS_INTEGRATION_25ms = 0xc,
    ALS_INTEGRATION_50ms = 0x8,
    ALS_INTEGRATION_100ms = 0x0,
    ALS_INTEGRATION_200ms = 0x1,
    ALS_INTEGRATION_400ms = 0x2,
    ALS_INTEGRATION_800ms = 0x3 };
  enum als_persist_t
  { ALS_PERSISTENCE_1 = 0x0,
    ALS_PERSISTENCE_2 = 0x1,
    ALS_PERSISTENCE_4 = 0x2,
    ALS_PERSISTENCE_8 = 0x3 };
  enum als_powmode_t
  { ALS_POWER_MODE_1 = 0x0,
    ALS_POWER_MODE_2 = 0x1,
    ALS_POWER_MODE_3 = 0x2,
    ALS_POWER_MODE_4 = 0x3 };
  enum { STATUS_OK = 0, STATUS_ERROR = 0xff };

  enum { I2C_ADDRESS = 0x10 };
  enum { COMMAND_ALS_SM = 0x00, ALS_SM_MASK = 0x1800, ALS_SM_SHIFT = 11 };
  enum { COMMAND_ALS_IT = 0x00, ALS_IT_MASK = 0x03c0, ALS_IT_SHIFT = 6 };
  enum { COMMAND_ALS_PERS = 0x00, ALS_PERS_MASK = 0x0030, ALS_PERS_SHIFT = 4 };
  enum { COMMAND_ALS_INT_EN = 0x00, ALS_INT_EN_MASK = 0x0002,
         ALS_INT_EN_SHIFT = 1 };
  enum { COMMAND_ALS_SD = 0x00,  ALS_SD_MASK = 0x0001, ALS_SD_SHIFT = 0 };
  enum { COMMAND_ALS_WH = 0x01 };
  enum { COMMAND_ALS_WL = 0x02 };
  enum { COMMAND_PSM = 0x03, PSM_MASK = 0x0006, PSM_SHIFT = 1 };
  enum { COMMAND_PSM_EN = 0x03, PSM_EN_MASK = 0x0001, PSM_EN_SHIFT = 0 };
  enum { COMMAND_ALS = 0x04 };
  enum { COMMAND_WHITE = 0x05 };
  enum { COMMAND_ALS_IF_L = 0x06, ALS_IF_L_MASK = 0x8000, ALS_IF_L_SHIFT = 15 };
  enum { COMMAND_ALS_IF_H = 0x06, ALS_IF_H_MASK = 0x4000, ALS_IF_H_SHIFT = 14 };

uint8_t getALSLux(int fd,float *lux);
uint8_t sendData(int fd,uint8_t command, uint16_t data);
uint8_t setGain(int fd,enum als_gain_t gain);
uint8_t setIntegrationTime(int fd,enum als_itime_t itime);
uint8_t sampleDelay(int fd);
uint8_t setPower(int fd,uint8_t on);

#endif